const router = require('koa-router')();
const index = require('../../app/model/mongodb/index');
const feeds = require('../../app/model/feeds.mongo');

// const ProductMasterSchema = require('../app/model/ProductMasterSchema.mongo');

router.prefix('/api/v1/feeds');

router.get('/', function (ctx, next) {
  ctx.body = 'this is a feeds response!'
});

/***********************
 *  feeds api
 ************************/
router.post('/products/:masterId/', async (ctx, next) =>{
  const sellerId = ctx.headers.sellerid;
  const mwsAuthToken = ctx.headers.mwsauthtoken;

  const masterId = ctx.params.masterId;


  // const productMaster = ProductMaster

  // let feedContent = feedsProductTemplate.amazonEnvelopeTemplate2xml(sellerId, "Update", [product]);
  // feedContent = mwsReorder(feedContent);

  try {
    // const r1 = feeds.initMockData();
    // const r2 = feeds.findProductMasterById('5f8a5189f3b6aa46dc53f0e4');
    const r3 = await feeds.findProductChanged('5f8a5189f3b6aa46dc53f0e4');
    // let json = await submitFeed.submitFeed(sellerId, mwsAuthToken, feedType, feedContent, [marketplaceid]);
    // console.log(json);
    ctx.response.status = 200;
    ctx.response.body = {
      data: {result: "success"},
    };
  } catch (error) {
    ctx.response.status = 500;
    ctx.response.body = {
      data: error,
    };
  }
});

module.exports = router;